<?php	
	$p = new pager;
	
	$limit = 20;
	
	$start = $p->find_start($limit);
	
	$count = mysql_num_rows(mysql_query("SELECT * FROM mau_tin_td WHERE giay_phep = 1"));
	
	$pages = $p->find_pages($count, $limit);
	
	mysql_query("SET character_set_results=utf8"); //lấy dữ liệu tiếng việt từ csdl
	
	$sql="SELECT *, 
				 DATE_FORMAT(ngay_dang,'%d-%m-%Y') AS ngay FROM mau_tin_td , 
				 linh_vuc_td  
		  WHERE mau_tin_td.ms_linh_vuc = linh_vuc_td.ms_linh_vuc 
		  		AND mau_tin_td.giay_phep = 1 
				AND DATE_ADD(ngay_dang, INTERVAL thoi_gian_song DAY) > NOW() 
		  ORDER BY mau_tin_td.ngay_dang DESC
		  LIMIT ".$start.", ".$limit;
		  
	$rs=mysql_query($sql);
	
	echo "<div style='height:50px;'><a href='index.php?noidung=dttd' class='com fr'>Đăng tin</a></div>";
	if(mysql_num_rows($rs) > 0){
		while($row = mysql_fetch_array($rs)){
			$ms_mt = $row[0];
			$ten_nha_td = $row[3];
			$ngay_dang = $row['ngay'];
			$noi_dang = $row[8];
			$linh_vuc = $row[17];
			$vi_tri = $row[4];
			$logo = $row[10];
			
			echo  "<div class='form' style='border:2px solid #99ccff; background-color:#f0f0f0;'>
						<table width='100%' cellpadding='2' cellspacing='0'>
							<tr>
								<td rowspan='5'><img width='110px' src='uploads/$logo' alt='No image' />&nbsp;</td>
								<td colspan='2' align='center'><h2><span><a href='index.php?noidung=td_v&&mt_td=$ms_mt'>$ten_nha_td</a></span></h2></td>
							</tr>
							<tr>
								<td width='100' align='right' valign='top'>Tuyển dụng: </td>
								<td><strong>$vi_tri</strong></td>
							</tr>
							<tr>
								<td align='right'>Nơi đăng: </td>
								<td><strong>$noi_dang</strong> &nbsp;|&nbsp;
											  Ngày đăng: <strong>$ngay_dang</strong></td>
							</tr>
							<tr>
								<td colspan='2'><p class='post-data'><a href='index.php?noidung=td_v&&mt_td=$ms_mt' class='com fr'>Xem chi tiết</a></p></td>
							</tr>
						</table>
					</div>";
		}
	}
	$page_list = $p->page_list($_GET['page'], $pages);
	echo "<p>";
	echo "<div class='pagenavi'>".$page_list."</div>";
	echo "</p>";
	echo 			"<div class='clr'></div>";
?>